"""
部署数据模式
"""
from datetime import datetime
from typing import Optional, Dict, Any
from pydantic import BaseModel


class DeploymentBase(BaseModel):
    """部署基础模式"""
    name: str
    version: str
    deployment_type: str = "rolling"  # rolling, blue_green, canary
    strategy: Optional[Dict[str, Any]] = None
    config: Optional[Dict[str, Any]] = None


class DeploymentCreate(DeploymentBase):
    """创建部署模式"""
    application_id: int
    environment_id: int


class DeploymentUpdate(BaseModel):
    """更新部署模式"""
    name: Optional[str] = None
    version: Optional[str] = None
    deployment_type: Optional[str] = None
    strategy: Optional[Dict[str, Any]] = None
    config: Optional[Dict[str, Any]] = None
    status: Optional[str] = None


class Deployment(DeploymentBase):
    """部署响应模式"""
    id: int
    status: str
    logs: Optional[str] = None
    error_message: Optional[str] = None
    started_at: Optional[datetime] = None
    completed_at: Optional[datetime] = None
    duration: Optional[int] = None
    created_at: datetime
    updated_at: datetime
    application_id: int
    environment_id: int
    creator_id: int

    class Config:
        from_attributes = True


class DeploymentHistory(BaseModel):
    """部署历史模式"""
    id: int
    action: str
    status: str
    message: Optional[str] = None
    config_snapshot: Optional[Dict[str, Any]] = None
    created_at: datetime

    class Config:
        from_attributes = True
